﻿using System.IO;
using System.Net;

namespace SimpleNoteLib.HttpRequests
{
    internal class HttpGetRequest : IHttpRequest
    {
        public string Address { get; set; }
        public IWebProxy Proxy { get; set; }
        public byte[] Data { get; set; }

        public HttpGetRequest()
        {
            Address = Config.SimpleNoteApiConfig.ApiAddress;
            Proxy = Config.SimpleNoteApiConfig.Proxy;
        }

        public HttpGetRequest(string address, IWebProxy proxy)
        {
            Address = address;
            Proxy = proxy;
        }

        public virtual string SendAndGetResponse()
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Address);

            request.Proxy = Proxy;
            request.Method = "GET";

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            string result = new StreamReader(response.GetResponseStream()).ReadToEnd();

            return result;
        }
    }
}
